package com.lh.module1.project.jpatest.controller;

import com.lh.module1.project.jpatest.entity.Student;
import com.lh.module1.project.jpatest.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lh
 * @Description: student相关控制层
 * @date 2021/3/24 11:54
 */
@RestController
@RequestMapping("/student")
public class StudentController {
	@Autowired
	private StudentService studentService;

	@GetMapping("/saveOne")
	public String saveOne(String sId, String sName, String sBirth, String sSex) {
		Student student = new Student(sId, sName, sBirth, sSex);
		studentService.saveOne(student);
		return "success";
	}

	@GetMapping("/delStudentBySid")
	public String delStudentBySid(String sId) {
		studentService.delStudentBySid(sId);
		return "success";
	}

	@GetMapping("/updateStudent")
	public String updateStudent(String sId, String sName, String sBirth, String sSex) {
		Student student = new Student(sId, sName, sBirth, sSex);
		studentService.updateStudent(student);
		return "success";
	}

	@GetMapping("/findAllStudent")
	public String findAllStudent() {
		List<Student> studentList = studentService.findAllStudent();
		studentList.forEach(student -> {
			System.out.println(student);
		});
		return "success";
	}

	@GetMapping("/findStudentBySid")
	public String findStudentBySid(String sId) {
		Student student = studentService.findStudentBySid(sId);
		System.out.println(student);
		return "success";
	}
}
